package com.lc.boot.initializer;

import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.WebApplicationInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;
import java.lang.reflect.Modifier;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * @author liuc
 * @date 2021/5/6
 * @description
 **/
//标注该注解会被tomcat扫描记录,在调用onStartup方法时会传递实现了该注解标注的接口的实现类作为第一个参数
@HandlesTypes(LcWebApplicationInitializer.class)
public class MySpringServletContainerInitializer implements ServletContainerInitializer {

    @Override
    public void onStartup(Set<Class<?>> lcWebAppInitializerClasses, ServletContext servletContext) throws ServletException {
        System.out.println("MySpringServletContainerInitializer come in...");
        if(lcWebAppInitializerClasses == null || lcWebAppInitializerClasses.size() == 0){
            return;
        }
        for (Class<?> lcWebAppInitializerClass : lcWebAppInitializerClasses) {
            try {
                LcWebApplicationInitializer initializer = (LcWebApplicationInitializer) lcWebAppInitializerClass.newInstance();
                initializer.startUp(servletContext);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}
